
/**
 * AppleIIGo
 * 2IMG Disk Image class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include <stdio.h>
#include "Motherboard.h"

#ifndef TWOIMGDISKIMAGE_H
#define TWOIMGDISKIMAGE_H

#define TWOIMGVERSION				1

typedef enum {
	TWOIMGFORMAT_GCR62_DOS,
	TWOIMGFORMAT_GCR62_PRODOS,
	TWOIMGFORMAT_NIB,
};

#define TWOIMGFLAGS_VOLUME			(1 << 8)
#define TWOIMGFLAGS_WRITEPROTECTED	(1 << 31)

struct TwoImgHeaderType {
	char id[4];
	char creator[4];
	UINT16 headerByteNum;
	UINT16 headerVersion;
	UINT32 diskImageFormat;
	UINT32 flags;
	UINT32 prodosBlockNum;
	UINT32 diskImageOffset;
	UINT32 diskImageByteNum;
	UINT32 commentOffset;
	UINT32 commentByteNum;
	UINT32 creatorOffset;
	UINT32 creatorByteNum;
};

class TwoImgDiskImage {
public:
	static bool isDiskImageValid(char * diskImagePath,
								 UINT32 * diskImageOffset,
								 UINT32 * diskImageByteNum,
								 char ** diskImageExtension,
								 UINT8 * diskVolume,
								 bool * isWriteProtectionForced);
private:
	static bool readHeader(FILE * diskImageFile,
						   UINT32 * diskImageOffset,
						   UINT32 * diskImageByteNum,
						   char ** diskImageExtension,
						   UINT8 * diskVolume,
						   bool * isWriteProtectionForced);
};

#endif
